package com.jxc.servlet.Session;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/Session/SessionIndex")
public class SessionIndexServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 获取用户会话session对象,这里的session对象与请求转发的session对象是同一个
        HttpSession session = req.getSession();
        // 提取session里user的信息
        String user = (String) session.getAttribute("user");
        resp.setContentType("text/html;charset=utf-8");
        resp.getWriter().print("<h1> user name is "+user+"</h1>");
    }
}
